syms m t k L0 g real
syms x(t) v(t)
assume(k>0); assume(m>0);
diffeq = m*diff(x(t),t,2) == -k*(x(t) - L0) - m*g
v(t) = diff(x(t),t)
IC = [x(0)==L0,v(0)==0]
sol = simplify(dsolve(diffeq,IC,symvar('x(t)')))
sol_with_nums = subs(sol,[L0,k,m,g],[1,10^5,2000,9.81])
fplot(sol_with_nums,[0,5],'Linewidth',2,'Color',[1,0,0])
ylim([0 1])
set(gca,'FontSize',14)
xlabel('Time (s)')
ylabel('Spring length (m)')
grid on